//
//  FivePicModeViewCell.m
//  XRmenu-HD
//
//  Created by shengchao yang on 11-12-3.
//  Copyright (c) 2011年 home user. All rights reserved.
//

#import "FivePicsModeViewCell.h"

@implementation FivePicsModeViewCell

-(id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier Customer:(NSString*)customer{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier Customer:customer];
    if (self) {
        if ([self viewWithTag:kTagOfStartBT]) {
            UIButton *btn =(UIButton *) [self viewWithTag:kTagOfStartBT];             
            [btn.titleLabel setFont:[UIFont fontWithName:@"Arial" size:20.0f]];
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [btn setBackgroundImage:[UIImage imageWithContentsOfFile:[XRmenuPublic getGeneralSkinImg:@"bt_detail.png"]] forState:UIControlStateNormal];
            [btn setTitle:loc(@"详细") forState:UIControlStateNormal];
        }
        if ([self viewWithTag:kTagOfStartBT+1]) {
            UIButton *btn =(UIButton *) [self viewWithTag:kTagOfStartBT+1]; 
            [btn.titleLabel setFont:[UIFont fontWithName:@"Arial" size:20.0f]];
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [btn setBackgroundImage:[UIImage imageWithContentsOfFile:[XRmenuPublic getGeneralSkinImg:@"bt_order.png"]] forState:UIControlStateNormal];
            [btn setTitle:loc(@"点单") forState:UIControlStateNormal];
        }
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
#pragma mark -
#pragma mark 重载button处理方法
-(void) buttonClicked:(id)sender
{
	NSInteger bid = [sender tag];
    if(bid ==(kTagOfStartBT+0)){//显示详细界面  
        [APPSESSION playSoundOnEvent:[XRmenuPublic getGeneralSkinImg:@"buttonClicked.caf"]];
        //1.修改当前菜品的下标位置
        [APPSESSION updateCurrentPluIndex:rowIndex];
        //2.通知主界面修改右边tableview的选中状态
        postN(kMessage_MainView_SelectMainViewPluPlu);
        //3.弹出显示详细信息界面
        postN(kMessage_RootView_PhotoPopoverViewDisplay);
    }
    else if(bid==kTagOfStartBT+1){//点单
        [APPSESSION playSoundOnEvent:[XRmenuPublic getGeneralSkinImg:@"buttonClicked.caf"]];
        //1.修改当前菜品的下标位置
        [APPSESSION updateCurrentPluIndex:rowIndex];
        //2.通知主界面修改右边tableview的选中状态
        postN(kMessage_MainView_SelectMainViewPluPlu);
        //3.插入点单数据
        XRmenuError *outErr=nil;
        [XRmenuCoreData insertNewDishOrder:APPSESSION.currentPluPlu Error:&outErr];
        //4.设置选中状态
        [self setDishSelected:YES];
        //5.界面上更新我的点单数量
        postN(kMessage_MainView_MyOrderNumberChanged);
    }
}
-(void) setData:(NSInteger) newRowIndex{
    rowIndex=newRowIndex;
    PluPlu *onePluPlu=[APPSESSION.pluPlus objectAtIndex:newRowIndex];

    if (onePluPlu.rsToDishOrder !=nil) {
        [self setDishSelected:YES];
    }
    else{
        [self setDishSelected:NO];
    }
    if([self viewWithTag:kTagOfStartImgV+1]){
        UIImageView *imgview = (UIImageView*)[self viewWithTag:kTagOfStartImgV+1];
        if (imgview) {
            XRmenuError* error = nil;
            UIImage *img=getDishGridImg(onePluPlu.ppPluPluId,error);//菜品图片
            [imgview setImage:img];
        }    
    }
	if ([self viewWithTag:kTagOfStartLabel]) {
		UILabel *tl = (UILabel*)[self viewWithTag:kTagOfStartLabel];
		if (tl) {
			NSString *txt = JsonFiled(onePluPlu.ppNames);
			[tl setText:txt];
		}
	}
    if([self viewWithTag:kTagOfStartLabel + 2]){
        UILabel *tl = (UILabel*)[self viewWithTag:kTagOfStartLabel + 2];
		if (tl) {
			NSString *txt = onePluPlu.ppCode;
			[tl setText:txt];
		}
    }
    if([self viewWithTag:kTagOfStartLabel + 3]){
        UILabel *tl = (UILabel*)[self viewWithTag:kTagOfStartLabel + 3];
		if (tl) {
			NSString *txt = JsonFiled(onePluPlu.ppRemarks);
			[tl setText:txt];
		}
    }
    if([self viewWithTag:kTagOfStartLabel + 4]){
        UILabel *tl = (UILabel*)[self viewWithTag:kTagOfStartLabel + 4];
		if (tl) {            
            NSString* unit=JsonFiled(onePluPlu.ppUnits);
            NSString* price  = [NSString stringWithFormat:@"%@%0.2f",[APPSESSION.allconfig getStringValueAtPath:@"System Config/currency"],[onePluPlu.ppPrice floatValue]];
            if ([onePluPlu.ppPrice floatValue]==0) {
                price=loc(@"时价");
            }
			[tl setText:[NSString stringWithFormat:@"%@/%@",price,unit]];
		}
    }
}
-(void) setDishSelected:(BOOL) isSelected{
    if ([self viewWithTag:kTagOfStartImgV+2]) {
        [self viewWithTag:kTagOfStartImgV+2].hidden=!isSelected;
    }
}
@end
